<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ko" xml:lang="ko">

<head>
	<title></title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" type="text/css" href="../css/base.css" media="all" />
	
<%
//String view = view;
	String view = "";
%>
</head>

<body id="wrap">
<jsp:include page="../bizring_header1.jsp"/>
	<div id="container">
		<!-- left-->		
	    <h2 class="hidden">sub_menu</h2>
		<div id="left_part">
			<div id="left_menu">
<%if(view == null || view.equals("")){%>
				<ul>
					<p><img src="../images/prize/left_title.gif" alt="Prize" /></p>
					<li><a href="prize now.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image23','','../images/prize/left_menu01_on.gif',1)" onblur="MM_swapImgRestore()" onfocus="MM_swapImage('Image23','','../images/prize/left_menu01_on.gif',1),this.blur()"><img src="../images/prize/left_menu01_off.gif" name="Image23" width="161" border="0" id="Image23" alt="Prize Now" /></a></li>
					<li><a href="last month.html"  onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image22','','../images/prize/left_menu02_on.gif',1)" onblur="MM_swapImgRestore()" onfocus="MM_swapImage('Image22','','../images/prize/left_menu02_on.gif',1),this.blur()"><img src="../images/prize/left_menu02_off.gif" name="Image22" width="161" border="0" id="Image22" alt="Last Month Winner" /></a></li>
					<li><a href="prize notice.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image24','','../images/prize/left_menu03_on.gif',1)" onblur="MM_swapImgRestore()" onfocus="MM_swapImage('Image24','','../images/prize/left_menu03_on.gif',1),this.blur()"><img src="../images/prize/left_menu03_off.gif" name="Image24" width="161" border="0" id="Image24" alt="Prize Notice" /></a></li>
					<li><a href="Prize Request_list.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image25','','../images/prize/left_menu04_on.gif',1)" onblur="MM_swapImgRestore()" onfocus="MM_swapImage('Image25','','../images/prize/left_menu04_on.gif',1),this.blur()"><img src="../images/prize/left_menu04_off.gif" name="Image25" width="161" border="0" id="Image25" alt="Prize Request" /></a></li>
				</ul>
<%}
else if(view.equals("k")){%>
				<ul>
					<p><img src="../images/prize/left_title.gif" alt="Prize" /></p>
					<li><a href="prize now.html?view=k" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image23','','../images/prize/left_menu01_on.gif',1)" onblur="MM_swapImgRestore()" onfocus="MM_swapImage('Image23','','../images/prize/left_menu01_on.gif',1),this.blur()"><img src="../images/prize/left_menu01_off.gif" name="Image23" width="161" border="0" id="Image23" alt="Prize Now" /></a></li>
					<li><a href="last month.html?view=k"  onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image22','','../images/prize/left_menu02_on.gif',1)" onblur="MM_swapImgRestore()" onfocus="MM_swapImage('Image22','','../images/prize/left_menu02_on.gif',1),this.blur()"><img src="../images/prize/left_menu02_off.gif" name="Image22" width="161" border="0" id="Image22" alt="Last Month Winner" /></a></li>
					<li><a href="prize notice.html?view=k" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image24','','../images/prize/left_menu03_on.gif',1)" onblur="MM_swapImgRestore()" onfocus="MM_swapImage('Image24','','../images/prize/left_menu03_on.gif',1),this.blur()"><img src="../images/prize/left_menu03_off.gif" name="Image24" width="161" border="0" id="Image24" alt="Prize Notice" /></a></li>
					<li><a href="Prize Request_list.html?view=k" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image25','','../images/prize/left_menu04_on.gif',1)" onblur="MM_swapImgRestore()" onfocus="MM_swapImage('Image25','','../images/prize/left_menu04_on.gif',1),this.blur()"><img src="../images/prize/left_menu04_off.gif" name="Image25" width="161" border="0" id="Image25" alt="Prize Request" /></a></li>
				</ul>
<%}%>
		    </div>
		</div>
	    <h2 class="hidden">contacts</h2>
		<div id="body_part">
			<div id="body_con">
				<p class="text_tit" style="padding:20px 0 0 16px ;">Untuk mengajukan usulan hadiah, kirim</p>
				<p class="text_bic"  style="padding:5px 0 0 16px;">
					SMS ke 0821-1234-2200 				
				</p>
			  <p class="text_orange" style="padding:5px 0 0 16px;"><img src="../images/common/ico_01.gif" alt="" align="absmiddle" /> Jika Anda belum menjadi pelanggan Biz-Ring otomatis akan didaftarkan.</p>
				<p></p>
				<div class="ta_top"></div>
				<div class="ta_bg">
					<div class="bs_con">
					<fieldset>
					<legend>prize_request</legend>
						<table class="board01" cellpadding="0" cellspacing="0" border="0" summary="prize_request">
							<caption style="position:absolute; width:0; height:0; font-size:0; line-height:0; overflow:hidden; visibility:hidden;">prize_request</caption>
							<colgroup>
								<col style="width:50px" />
								<col style="width:135px" />
								<col style="width:405px" />
							</colgroup>
							<thead>
								<tr>
									<th scope="col"><img src="../images/prize/board_tit_01.gif" alt="No" align="absmiddle" /></th>
									<th scope="col"><img src="../images/prize/board_tit_02.gif" alt="H.P" align="absmiddle" /></th>
									<th scope="col"><img src="../images/prize/board_tit_03.gif" alt="Order for Prize" align="absmiddle" /></th>
								</tr>
							</thead>
							<tbody>
								<tr>
									<td colspan="3" height="10px" class="line"></td>
								</tr>
<%
	int rows = 12;
	int currPage = (request.getParameter("page") == null ? 1 : 
							request.getParameter("page").equals("0") ? 1 : Integer.parseInt(request.getParameter("page")));

	String connectionUrl = "jdbc:sqlserver://112.78.183.95:14333;databaseName=bizring";
	String userid = "sa";
	String passwd = "qlalf@sql";
	
	// Declare the JDBC objects.
	java.sql.Connection con = null;
	java.sql.Statement stmt = null;
	java.sql.Statement stmt2 = null;
	java.sql.ResultSet rs = null;
	java.sql.ResultSet rs2 = null;
	
	// Establish the connection.
	Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//out.println(currPage);
	try {
		// Create and execute an SQL statement that returns some data.
		String SQL = "SELECT msisdn, title, RowNum, id as row_id FROM " +
		 "( SELECT id, t.msisdn, t.title, ROW_NUMBER() OVER (ORDER BY id desc) AS RowNum " +
     	 "FROM web_board t WHERE t.category = 'prize_req') AS MyDerivedTable WHERE MyDerivedTable.RowNum BETWEEN " + 
     	 (rows * (currPage - 1) + 1) + " AND " + (rows * currPage);
		
		String cnt = "SELECT COUNT(*) AS cnt FROM web_board t WHERE t.category = 'prize_req'";
		
		con = java.sql.DriverManager.getConnection(connectionUrl, userid, passwd);
		stmt = con.createStatement();
		stmt2 = con.createStatement();
		rs = stmt2.executeQuery(SQL);
		rs2 = stmt.executeQuery(cnt);
		
		int recodes = 0;
		
		while(rs2.next()){
			recodes = rs2.getInt(1);
		}

		int displayedRow = 0;
		// Iterate through the data in the result set and display it.
		while (rs.next()) {
			displayedRow++;
			out.println("<tr>");
			out.println("<td>" + (recodes - ((rows*currPage)-12)) + "</td>"); 
			out.println("<td>" + rs.getString("msisdn").substring(rs.getString("msisdn").length()-4, rs.getString("msisdn").length()) + "</td>");
			if(view == null || view.equals("")){
				out.println("<td class=\"title\">" + rs.getString("title") + "</td>");
			}
			else if(view.equals("k")){
				out.println("<td class=\"title\"><a href=\"prize_modify.jsp?view=k&id=" + rs.getString("row_id") + "\">" + rs.getString("title") + "</a></td>");
			}
			out.print("</tr>");
			recodes--;
		}
		for (int i = displayedRow; i < 12; i++)
			out.println("<tr><td class=\"date\"></td><td class=\"title\"></td></tr>");
    } catch (java.sql.SQLException e) {   
        e.printStackTrace();   
    } finally{   
        try {   
            if(stmt !=null) stmt.close();   
            if(con !=null) con.close();   
        } catch (java.sql.SQLException e) {   
            e.printStackTrace();   
        }   
    }   
%>
								<tr>
									<td colspan="3" height="10px" class="line"></td>
								</tr>
							</tbody>
						</table>
						<div class="board_navigation">
<%
	
	try {
		String counter = "SELECT count(1) as counter FROM web_board WHERE category = 'prize_req'";
		con = java.sql.DriverManager.getConnection(connectionUrl, userid, passwd);
		stmt = con.createStatement();
		rs = stmt.executeQuery(counter);
		int totalRecode = 0;
		while (rs.next()) {
			totalRecode = rs.getInt(1);
		}
		
		int totalPage = (int)(Math.ceil((double)totalRecode/rows));
		int viewFirst = ((int)(currPage-1)/10) * 10;
		int viewLast = ((int)(currPage-1)/10) * 10 + 9;
		
		//out.println(viewFirst); 
		//out.println(viewLast);
		//out.println(totalPage);	
		//out.println(currPage);	
		//out.println(totalRecode); 
		String href = "";
		
		if(view == null || view.equals("")){
			if(viewFirst != 0){
				out.print("<a href=\"./prize_request_list.jsp?page=1\"><b>[First]</b></a>&nbsp;&nbsp; ");
				out.print("<a href=\"./prize_request_list.jsp?page=" + viewFirst + "\"><b>[Prev]</b></a>&nbsp;&nbsp; ");
			}
			
			for (int i = 0;i < totalPage; i++){						
				if (i == (currPage - 1)){
					href = "<span class=\"text_red\">" + (i + 1) + "</span>&nbsp;";
					out.print(href + " ");
				}
				else if( (i >= viewFirst) && (i <= viewLast) ){			
					href = "<a href=\"./prize_request_list.jsp?page=" + (i + 1) + "\">" + (i + 1) + "</a>&nbsp;&nbsp;";
					out.print(href + " ");
				}
			}
			
			if( (int)viewLast/10 != (int)totalPage/10){
				out.print("&nbsp;&nbsp;<a href=\"./prize_request_list.jsp?page=" + (viewLast + 2) + "\"><b>[Next]</b></a>");
				out.print("&nbsp;&nbsp;<a href=\"./prize_request_list.jsp?page=" + totalPage + "\"><b>[Last]</b></a> ");
			}
		}
		else if(view.equals("k")){
			if(viewFirst != 0){
				out.print("<a href=\"./prize_request_list.jsp?view=k&page=1\"><b>[First]</b></a>&nbsp;&nbsp; ");
				out.print("<a href=\"./prize_request_list.jsp?view=k&page=" + viewFirst + "\"><b>[Prev]</b></a>&nbsp;&nbsp; ");
			}
			
			for (int i = 0;i < totalPage; i++){						
				if (i == (currPage - 1)){
					href = "<span class=\"text_red\">" + (i + 1) + "</span>&nbsp;";
					out.print(href + " ");
				}
				else if( (i >= viewFirst) && (i <= viewLast) ){			
					href = "<a href=\"./prize_request_list.jsp?view=k&page=" + (i + 1) + "\">" + (i + 1) + "</a>&nbsp;&nbsp;";
					out.print(href + " ");
				}
			}
			
			if( (int)viewLast/10 != (int)totalPage/10){
				out.print("&nbsp;&nbsp;<a href=\"./prize_request_list.jsp?view=k&page=" + (viewLast + 2) + "\"><b>[Next]</b></a>");
				out.print("&nbsp;&nbsp;<a href=\"./prize_request_list.jsp?view=k&page=" + totalPage + "\"><b>[Last]</b></a> ");
			}
		}		
	} catch (java.sql.SQLException e) {
		e.printStackTrace();
	} finally {
		try {   
            if(stmt !=null) stmt.close();   
            if(con !=null) con.close();   
        } catch (java.sql.SQLException e) {   
            e.printStackTrace();   
        }
	}
%>						
						</div>
<%if(view == null || view.equals("")){
}
else if(view.equals("k")){%>
						<div class="clear" style="padding-top:10px;text-align:right;"><a href="prize_write.html?view=k" onfocus="this.blur()"><img src="../images/common/btn_write.gif" alt="" /></a></div>
<%}%>					
					</fieldset>	
					</div>					
				</div>
				<div class="ta_bot"></div>
			</div>		
			<div class="clear"></div>
			<div class="pri_text">
				<ul>
					<li class="text_orange"><img src="../images/common/ico_01.gif" alt="" align="absmiddle" /> Anda dapat mengajukan usulan hadiah apa yang menarik untuk bulan depan</li>
					<li class="text_orange"><img src="../images/common/ico_01.gif" alt="" align="absmiddle" /> Kami hanya dapat menerima 3 SMS saja tiap hari dari nomor telepon yang sama</li>
				</ul>
			</div>
		</div>
	</div>
<jsp:include page="../bizring_footer1.jsp"/>
</BODY>
</HTML>
